package krao.data;

import java.util.ArrayList;

/**
 * Class for storing data for one tbox class. Also stored here are the
 * superclasses and subclasses of this class and the properties, in whose
 * domain/range this class is.
 * 
 * @author Pepe
 * 
 */
public class TBoxClass {
	private String name;
	ArrayList<String> superClasses;
	private ArrayList<String> subClasses;
	private ArrayList<TBoxProperty> domainOf;
	private ArrayList<TBoxProperty> rangeOf;

	public TBoxClass(String newClassName) {
		this.setName(newClassName);
		this.superClasses = new ArrayList<String>();
		this.setSubClasses(new ArrayList<String>());
		this.setDomainOf(new ArrayList<TBoxProperty>());
		this.setRangeOf(new ArrayList<TBoxProperty>());
	}

	/**
	 * Add new superclass, if it was not present yet
	 * 
	 * @param superClass
	 *            name of the class to be added
	 */
	public void addSuperClass(String superClass) {
		if (superClasses != null && !superClasses.contains(superClass)) {
			superClasses.add(superClass);
		}
	}

	/**
	 * Add new subclass, if it was not present yet
	 * 
	 * @param subClass
	 *            name of the class to be added
	 */
	public void addSubClass(String subClass) {
		if (getSubClasses() != null && !getSubClasses().contains(subClass)) {
			getSubClasses().add(subClass);
		}
	}

	/**
	 * Add information that this class belongs to domain of property @propWithThisClassAsItsDomain
	 * 
	 * @param propWithThisClassAsItsDomain
	 */
	public void setIsDomainOf(TBoxProperty propWithThisClassAsItsDomain) {
		if (getDomainOf() != null
				&& !getDomainOf().contains(propWithThisClassAsItsDomain)) {
			getDomainOf().add(propWithThisClassAsItsDomain);
		}
	}

	/**
	 * Add information that this class belongs to range of property @propWithThisClassAsItsRange
	 * 
	 * @param propWithThisClassAsItsRange
	 */
	public void setIsRangeOf(TBoxProperty propWithThisClassAsItsRange) {
		if (getRangeOf() != null && !getRangeOf().contains(propWithThisClassAsItsRange)) {
			getRangeOf().add(propWithThisClassAsItsRange);
		}
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder(String.format("%s[Super:", getName()));
		for (String oneClass : superClasses) {
			sb.append(oneClass);
			sb.append(", ");
		}
		sb.append("\tSub:");
		for (String oneClass : getSubClasses()) {
			sb.append(oneClass);
			sb.append(", ");
		}
		sb.append("]\n\t[DomainOf:");
		for (TBoxProperty oneClass : getDomainOf()) {
			sb.append(oneClass.getName());
			sb.append(", ");
		}
		sb.append("\tRangeOf:");
		for (TBoxProperty oneClass : getRangeOf()) {
			sb.append(oneClass.getName());
			sb.append(", ");
		}
		sb.append("]\n");
		return sb.toString();
	}

	public ArrayList<String> getSubClasses() {
		return subClasses;
	}

	public void setSubClasses(ArrayList<String> subClasses) {
		this.subClasses = subClasses;
	}

	public ArrayList<TBoxProperty> getDomainOf() {
		return domainOf;
	}

	public void setDomainOf(ArrayList<TBoxProperty> domainOf) {
		this.domainOf = domainOf;
	}

	public ArrayList<TBoxProperty> getRangeOf() {
		return rangeOf;
	}

	public void setRangeOf(ArrayList<TBoxProperty> rangeOf) {
		this.rangeOf = rangeOf;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}
